package com.hemerasolutions.v2trainer.model.schedule;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;

import com.hemerasolutions.v2trainer.model.base.BaseModel;
import com.hemerasolutions.v2trainer.model.interfaces.BaseModelInterface;
import com.hemerasolutions.v2trainer.model.modality.Modality;

@Entity
public class Schedule extends BaseModel implements BaseModelInterface {
 
	private static final long serialVersionUID = 1L;

    @Column(length = 50)
	private String name;
    
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)		
    private Date beginDate;

	@Column
	private int year;
	
	@Column
	private int weeks;
    
	@Column
	private int level;
	
	@ManyToOne 
    private Modality modality;
	
	@OneToOne(cascade=CascadeType.ALL, fetch=FetchType.LAZY) 
   private Availability availability;

	@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY) 
	private List<CycleType> cycleTypes;
	
	
	public Schedule() {
		super();
		this.availability = new Availability();
		this.cycleTypes = new ArrayList<CycleType>();
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public String getName() {
		return name;
	}

	public Date getBeginDate() {
		return beginDate;
	}

	public int getYear() {
		return year;
	}

	public int getWeeks() {
		return weeks;
	}

	public Modality getModality() {
		return modality;
	}

	public List<CycleType> getCycleTypes() {
		return cycleTypes;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}

	public void setYear(int year) {
		this.year = year;
	}

	public void setWeeks(int weeks) {
		this.weeks = weeks;
	}

	public void setModality(Modality modality) {
		this.modality = modality;
	}

	public void setCycleTypes(List<CycleType> cycleTypes) {
		this.cycleTypes = cycleTypes;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public Availability getAvailability() {
		return availability;
	}

	public void setAvailability(Availability availability) {
		this.availability = availability;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((availability == null) ? 0 : availability.hashCode());
		result = prime * result
				+ ((beginDate == null) ? 0 : beginDate.hashCode());
		result = prime * result
				+ ((cycleTypes == null) ? 0 : cycleTypes.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + level;
		result = prime * result
				+ ((modality == null) ? 0 : modality.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + weeks;
		result = prime * result + year;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Schedule other = (Schedule) obj;
		if (availability == null) {
			if (other.availability != null)
				return false;
		} else if (!availability.equals(other.availability))
			return false;
		if (beginDate == null) {
			if (other.beginDate != null)
				return false;
		} else if (!beginDate.equals(other.beginDate))
			return false;
		if (cycleTypes == null) {
			if (other.cycleTypes != null)
				return false;
		} else if (!cycleTypes.equals(other.cycleTypes))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (level != other.level)
			return false;
		if (modality == null) {
			if (other.modality != null)
				return false;
		} else if (!modality.equals(other.modality))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (weeks != other.weeks)
			return false;
		if (year != other.year)
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Schedule [id=" + id + ", name=" + name + ", beginDate="
				+ beginDate + ", year=" + year + ", weeks=" + weeks
				+ ", level=" + level + ", modality=" + modality
				+ ", availability=" + availability + ", cycleTypes="
				+ cycleTypes + "]";
	}
	

//	public Schedule(Date beginDate, List<CycleType> cycleTypes, Modality modality,
//	int year) {
//super();
//
//this.beginDate = beginDate;
//this.cycleTypes = cycleTypes;
//this.modality = modality;
//this.year = year;
//GregorianCalendar base = new GregorianCalendar();
//base.set(Calendar.YEAR, this.year);
//this.weeks = base.getMaximum(Calendar.WEEK_OF_YEAR);
//}
	
}
 
